<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['employee:student:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['employee:student:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['employee:student:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['employee:student:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="studentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="是否残疾" align="center" prop="id" />
      <el-table-column label="考生号" align="center" prop="examNo" />
      <el-table-column label="身份证号" align="center" prop="idCard" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="民族" align="center" prop="nation" />
      <el-table-column label="政治面貌" align="center" prop="politic" />
      <el-table-column label="学历" align="center" prop="education" />
      <el-table-column label="专业id" align="center" prop="majorId" />
      <el-table-column label="专业" align="center" prop="majorName" />
      <el-table-column label="培养方式" align="center" prop="cultivationMode" />
      <el-table-column label="生源所在地代码" align="center" prop="locationCode" />
      <el-table-column label="生源所在地" align="center" prop="location" />
      <el-table-column label="城乡生源" align="center" prop="urbanRural" />
      <el-table-column label="学制" align="center" prop="eduEnriched" />
      <el-table-column label="入学时间" align="center" prop="enrollmentTime" />
      <el-table-column label="毕业时间" align="center" prop="graduationTime" />
      <el-table-column label="困难生类别" align="center" prop="difficultStudents" />
      <el-table-column label="所在院系" align="center" prop="deptName" />
      <el-table-column label="所在院系id" align="center" prop="deptId" />
      <el-table-column label="所在班级" align="center" prop="classesName" />
      <el-table-column label="所在班级id" align="center" prop="classesId" />
      <el-table-column label="学号" align="center" prop="stuNo" />
      <el-table-column label="出生日期" align="center" prop="birthday" />
      <el-table-column label="手机号码" align="center" prop="phone" />
      <el-table-column label="电子邮箱" align="center" prop="email" />
      <el-table-column label="电子邮箱" align="center" prop="qq" />
      <el-table-column label="家庭地址" align="center" prop="homeAddress" />
      <el-table-column label="家庭电话" align="center" prop="homePhone" />
      <el-table-column label="家庭邮编" align="center" prop="homePost" />
      <el-table-column label="是否低保家庭" align="center" prop="livingAllowances" />
      <el-table-column label="是否退役军人" align="center" prop="retiredSoldier" />
      <el-table-column label="是否残疾" align="center" prop="disability" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['employee:student:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['employee:student:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改学生对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="考生号" prop="examNo">
          <el-input v-model="form.examNo" placeholder="请输入考生号" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="民族" prop="nation">
          <el-input v-model="form.nation" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="政治面貌" prop="politic">
          <el-input v-model="form.politic" placeholder="请输入政治面貌" />
        </el-form-item>
        <el-form-item label="学历" prop="education">
          <el-input v-model="form.education" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="专业id" prop="majorId">
          <el-input v-model="form.majorId" placeholder="请输入专业id" />
        </el-form-item>
        <el-form-item label="专业" prop="majorName">
          <el-input v-model="form.majorName" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="培养方式" prop="cultivationMode">
          <el-input v-model="form.cultivationMode" placeholder="请输入培养方式" />
        </el-form-item>
        <el-form-item label="生源所在地代码" prop="locationCode">
          <el-input v-model="form.locationCode" placeholder="请输入生源所在地代码" />
        </el-form-item>
        <el-form-item label="生源所在地" prop="location">
          <el-input v-model="form.location" placeholder="请输入生源所在地" />
        </el-form-item>
        <el-form-item label="城乡生源" prop="urbanRural">
          <el-input v-model="form.urbanRural" placeholder="请输入城乡生源" />
        </el-form-item>
        <el-form-item label="学制" prop="eduEnriched">
          <el-input v-model="form.eduEnriched" placeholder="请输入学制" />
        </el-form-item>
        <el-form-item label="入学时间" prop="enrollmentTime">
          <el-input v-model="form.enrollmentTime" placeholder="请输入入学时间" />
        </el-form-item>
        <el-form-item label="毕业时间" prop="graduationTime">
          <el-input v-model="form.graduationTime" placeholder="请输入毕业时间" />
        </el-form-item>
        <el-form-item label="困难生类别" prop="difficultStudents">
          <el-input v-model="form.difficultStudents" placeholder="请输入困难生类别" />
        </el-form-item>
        <el-form-item label="所在院系" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入所在院系" />
        </el-form-item>
        <el-form-item label="所在院系id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入所在院系id" />
        </el-form-item>
        <el-form-item label="所在班级" prop="classesName">
          <el-input v-model="form.classesName" placeholder="请输入所在班级" />
        </el-form-item>
        <el-form-item label="所在班级id" prop="classesId">
          <el-input v-model="form.classesId" placeholder="请输入所在班级id" />
        </el-form-item>
        <el-form-item label="学号" prop="stuNo">
          <el-input v-model="form.stuNo" placeholder="请输入学号" />
        </el-form-item>
        <el-form-item label="出生日期" prop="birthday">
          <el-input v-model="form.birthday" placeholder="请输入出生日期" />
        </el-form-item>
        <el-form-item label="手机号码" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="电子邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入电子邮箱" />
        </el-form-item>
        <el-form-item label="电子邮箱" prop="qq">
          <el-input v-model="form.qq" placeholder="请输入电子邮箱" />
        </el-form-item>
        <el-form-item label="家庭地址" prop="homeAddress">
          <el-input v-model="form.homeAddress" placeholder="请输入家庭地址" />
        </el-form-item>
        <el-form-item label="家庭电话" prop="homePhone">
          <el-input v-model="form.homePhone" placeholder="请输入家庭电话" />
        </el-form-item>
        <el-form-item label="家庭邮编" prop="homePost">
          <el-input v-model="form.homePost" placeholder="请输入家庭邮编" />
        </el-form-item>
        <el-form-item label="是否低保家庭" prop="livingAllowances">
          <el-input v-model="form.livingAllowances" placeholder="请输入是否低保家庭" />
        </el-form-item>
        <el-form-item label="是否退役军人" prop="retiredSoldier">
          <el-input v-model="form.retiredSoldier" placeholder="请输入是否退役军人" />
        </el-form-item>
        <el-form-item label="是否残疾" prop="disability">
          <el-input v-model="form.disability" placeholder="请输入是否残疾" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStudent, getStudent, delStudent, addStudent, updateStudent, exportStudent } from "@/api/employee/student";

export default {
  name: "Student",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学生表格数据
      studentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        examNo: null,
        idCard: null,
        name: null,
        sex: null,
        nation: null,
        politic: null,
        education: null,
        majorId: null,
        majorName: null,
        cultivationMode: null,
        locationCode: null,
        location: null,
        urbanRural: null,
        eduEnriched: null,
        enrollmentTime: null,
        graduationTime: null,
        difficultStudents: null,
        deptName: null,
        deptId: null,
        classesName: null,
        classesId: null,
        stuNo: null,
        birthday: null,
        phone: null,
        email: null,
        qq: null,
        homeAddress: null,
        homePhone: null,
        homePost: null,
        livingAllowances: null,
        retiredSoldier: null,
        disability: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询学生列表 */
    getList() {
      this.loading = true;
      listStudent(this.queryParams).then(response => {
        this.studentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        examNo: null,
        idCard: null,
        name: null,
        sex: null,
        nation: null,
        politic: null,
        education: null,
        majorId: null,
        majorName: null,
        cultivationMode: null,
        locationCode: null,
        location: null,
        urbanRural: null,
        eduEnriched: null,
        enrollmentTime: null,
        graduationTime: null,
        difficultStudents: null,
        deptName: null,
        deptId: null,
        classesName: null,
        classesId: null,
        stuNo: null,
        birthday: null,
        phone: null,
        email: null,
        qq: null,
        homeAddress: null,
        homePhone: null,
        homePost: null,
        livingAllowances: null,
        retiredSoldier: null,
        disability: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学生";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStudent(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改学生";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateStudent(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStudent(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除学生编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delStudent(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有学生数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportStudent(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
